import 'package:boss/models/material.dart' as material;

import 'package:boss/ui/widget/center_title_app_bar.dart';
import 'package:flutter/material.dart';
import 'package:hi_common/hi_common.dart';
import 'package:provider/provider.dart';
import 'package:router/annotation.dart';

import 'provider/material_detail_provider.dart';
import 'widget/material_detail_browser.dart';

@RouterConfig(MaterialDetailPage.pageName)
class MaterialDetailPage extends StatefulWidget {
  static const pageName = '/materialDetailPage';

  @Autowired()
  final material.Material data;

  const MaterialDetailPage({this.data});

  @override
  _MaterialDetailPageState createState() => _MaterialDetailPageState('加料/配菜详情');
}

class _MaterialDetailPageState extends BaseState<MaterialDetailPage> {
  _MaterialDetailPageState(String pageName) : super(pageName);

  bool get isUpdate => widget.data != null && widget.data.id != null;

  @override
  Widget build(BuildContext context) {
    return MultiProvider(
      providers: [
        ChangeNotifierProvider(
          create: (context) => MaterialDetailProvider(data: widget.data),
        )
      ],
      child: Scaffold(
        appBar: CenterTitleAppBar(
          title: isUpdate ? '加料/配菜详情' : '新增加料/配菜',
        ),
        body: MaterialDetailBrowser(),
      ),
    );
  }
}
